package com.moresir.validatetools.rules.list.other;


import com.moresir.validatetools.impl.Form;
import com.moresir.validatetools.rules.list.AbstractRule;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Optional;

/**
 * if attr  in (value1, value2)
 */
public class RuleIn extends AbstractRule {
    @Override
    public boolean isOkay(Form f) {
        Optional<String> s = f.getString(rule.getField());
        String contain = rule.getParams().get(0);
        ArrayList<String> containList = new ArrayList<>(Arrays.asList(contain.split(",")));
        boolean res = s.filter(str -> containList.contains(str)).isPresent();
        return res;
    }
}